/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package descente;

import java.util.Random;

/**
 *
 * @author Hippolyte
 */
public class Descente {
    
    private static String solve1(float x) {

        float xtemp, precision, eta, orig = x;
        eta = 0.01f;
        precision = 0.001f;
        xtemp = x;



        while (Math.abs(2 * xtemp) > precision) {
            xtemp = x;
            x = xtemp - eta * (2 * xtemp);
        }
        
        return "Résultat en partant de x =" + orig + " : " + x;
        
    }
    
    public static float f2(float x){
        float xtemp, precision, eta;
        eta = 0.01f;
        precision = 0.001f;
        xtemp = x;

        while (Math.abs(4 * (xtemp*xtemp*xtemp) - 33 * (xtemp*xtemp) 
                + 82 * xtemp - 61) > precision) {
            xtemp = x;
            x = xtemp - eta * (4 * (xtemp*xtemp*xtemp) - 33 * (xtemp*xtemp) 
                    + 82 * xtemp - 61);
        }
        return x;
    }
    
    
    private static String solve2(float x) {

        return "Résultat en partant de x = " + x + " : " + f2(x);
        
    }
    
    private static String solve3(float x, float y) {

        float precision, eta, origx = x, origy = y;
        eta = 0.01f;
        precision = 0.001f;

        while (Math.abs(2 * x - 3) > precision || Math.abs(2 * y + 7) > precision) {
            
            if (Math.abs(2 * x - 3) > precision){
                x = x - eta * (2 * x - 3);
            }
            if (Math.abs(2 * y + 7) > precision) {
                y = y - eta * (2 * y + 7);
            }
            
        }
        
        return "Résultat en partant de x = " + origx + " et y = " + origy + " : x=" + x + ", y=" + y;
        
    }
    



    

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        
       System.out.println(solve2(5));
        
    }
}
